package com.act;

import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;

public class PhoneStateChangeListener extends PhoneStateListener {

	private static final String TAG = LogUtil.getClassName(PhoneStateChangeListener.class);
	
	private NotificationService notifyService = null;
	
	public PhoneStateChangeListener(NotificationService notificationService)
	{
		notifyService = notificationService;
	}
	
	@Override
	public void onDataConnectionStateChanged(int state) {
		super.onDataConnectionStateChanged(state);
		
		Log.d(TAG, getPhoneState(state));
		if(state == TelephonyManager.DATA_DISCONNECTED)
		{
			notifyService.reconnect();
		}
	}
	
	private String getPhoneState(int state)
	{
		switch(state)
		{
		case TelephonyManager.DATA_CONNECTED:
			return "DATA_CONNECTED";
		case TelephonyManager.DATA_DISCONNECTED:
			return "DATA_DISCONNECTED";
		case TelephonyManager.DATA_CONNECTING:
			return "DATA_CONNECTING";
		}
		
		return "DATA<UNKOWN>";
	}
}
